import React from 'react'
import { connect } from 'dva'
import { DatePicker  } from 'antd'
import moment from 'moment'


const DataDate =(props)=>{
    const changeDate=val=>{
        const payload=props.location
        payload.query.date=val.format('YYYY-MM-DD')

        props.dispatch({
          type: `app/changeRouter`,
          payload
        })
      }
      return(
        <dl className='dataDate'>
              <dt>数据日期：</dt>
              <dd>
                <DatePicker 
                    onChange={changeDate} 
                    value={moment(props.date||props.lastDate, 'YYYY-MM-DD')} 
                    disabledDate={current => props.lastDate?((current < moment(props.firstDate, 'YYYY-MM-DD')) || (current > moment(props.lastDate, 'YYYY-MM-DD'))):false}
                    format={'YYYY-MM-DD'} 
                    allowClear={false}
                    disabled={props.disabled}
                />
              </dd>
            </dl>
    )
}


export default connect()(DataDate)
